import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, OneToOne, OneToMany } from "typeorm";
import { UserExtend } from './UserExtend'
import { Posts } from './Posts'

@Entity()
export class User {
    // 主键且自动自增的
    @PrimaryGeneratedColumn(
        {
            type: 'int',
            name: 'id',
            comment: '主键id'
        }
    )
    id: number;

    @Column({
        type: 'varchar', //字符类型
        nullable: true, //值是否可以为null
        length: 50,    //最大长度
        unique: true,  //是否为唯一
        name: 'username', // 如果是一样的可以不指定
        comment: '用户名'
    })
    username: string;

    @Column({
        type: 'varchar',
        nullable: true,
        length: 100,
        comment: '密码'
    })
    password: string;

    @Column('tinyint', {
        nullable: false,
        default: () => 0,
        name: 'is_del',
        comment: '是否删除,1表示删除,0表示正常'
    })
    isDel: number;
    @Column({
        type: 'int',
        nullable: true, //值是否可以为null
        comment: '年龄'
    })
    age: number;

    @CreateDateColumn({
        nullable: false,
    })
    createTime: Date;

    @UpdateDateColumn({
        nullable: false,
    })
    updateTime: Date;

    //一对一
    @OneToOne(type => UserExtend, userExtend => userExtend.user)
    userDetail: UserExtend
    //一对多
    @OneToMany(type => Posts, posts => posts.user)
    posts: Posts[]
}
